package com.itedge.infrastructure.web.taskhandler;

import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.itedge.infrastructure.web.dto.TaskAvailabilityResponse;

/**
 * Interface for task data handlers.
 * 
 * @author jhe
 *
 * @param <T>
 * @param <O>
 */
public interface ITaskDataHandler<T, O> {
	
	/**
	 * This method load task data and all related data and adds it to the model.
	 * 
	 * @param taskId
	 * @param linkedObject
	 * @param forHistory
	 * @return map with loaded task data instance and all related data
	 */
	public Map<String,?> loadTaskData(String taskId, O linkedObject, Boolean forHistory)
		throws TaskHandlerException;
	
	/**
	 * This method saves task data
	 * 
	 * @param taskData
	 */
	public void saveTaskData(T taskData);
	
	/**
	 * This method saves task data and completes related process engine task.
	 * 
	 * @param taskData
	 * @param linkedObject
	 * @param taskId
	 */
	public void saveTaskDataAndPushProcess(T taskData, O linkedObject, String taskId);
	
	/**
	 * This method decides if task with given taskId is still available and if it is, 
	 * then locks it - be sure to only call this method immediately before task saving.
	 * 
	 * @param taskId
	 * @param lockedBy
	 * @param locale
	 * @return  task availability response
	 */
	public TaskAvailabilityResponse requestTaskAvailabilityAndLockTask(String taskId, String lockedBy, Locale locale);
	
	/**
	 * Call this method to check if task with given taskId is available (not completed).
	 * 
	 * @param taskId
	 * @param locale
	 * @return task availability response
	 */
	public TaskAvailabilityResponse requestTaskAvailability(String taskId, Locale locale);
	
	/**
	 * This method is used to bind values to task data bean from request and linked value object.
	 * 
	 * @param request
	 * @param linkedObject
	 * @return task data entity with all values from request bound
	 */
	public T bindTaskData(HttpServletRequest request, O linkedObject) 
		throws TaskHandlerException;

}
